rule_0={"name": "柏源","height":185}
print(rule_0["name"])
rule_0["passion"]="full"
print(rule_0)
#6-1
friend={
    "first_name": "lily", 
    "last_name": "wilson", 
    "age": 31, 
    "city": "shenzhen",
    }
#打印字典，反正现在是不能直接字典名称
#print("friend")
print(friend["first_name"])
print(friend["last_name"])
print(friend["age"])
print(friend["city"])
#6-2
favourite_num={"mom": 66, "dad":45, "yu": 36, "me":8}
print("mom favourite number is "+str(favourite_num["mom"]))
print("dad favourite number is "+str(favourite_num["dad"]))
print("yu favourite number is "+str(favourite_num["yu"]))
print("my favourite number is "+str(favourite_num["me"]))
#6-3in,for,if,reserve
alphabet_list={
    "in": "某个元素是否在列表当中出现", 
    "for": "遍历列表当中所有的元素", 
    "if": "条件测试，返回值为True或者是False", 
    "reserve": "现阶段所接触到的是，排序反转",
    }
print("in\n"+alphabet_list["in"])
print("for\n"+alphabet_list["for"])
print("if\n"+alphabet_list["if"])
print("reserve\n"+alphabet_list["reserve"])
favourite_languages={
    "jen": "python",
    "sarah": "c",
    "edward": "ruby",
    "phil": "python",
    }
friends = ["phil","edward"]
for name in favourite_languages:
	if name in friends:
		print(name)
		print("hi " + name.title() + 
			", i see your favourite language is " +
			favourite_languages[name].title() + ".")
		#这里括号里的name不是字典里的键，而是变量，也就是说变量在字典引用里不用加引号，键需要
			#favourite_languages["name"].title() + ".")
favourite_languages={
    "jen": "python",
    "sarah": "c",
    "edward": "ruby",
    "phil": "python",
    }
for name in sorted(favourite_languages.keys(),reverse=True):
    print(name.title() + ", thank you for taking the poll")	
#6-4
for method,alphabet in alphabet_list.items():
	print(method+":\n"+alphabet)
alphabet_list["sort"]= "列表排序，一般按照字母顺序"
alphabet_list["del"] = "删除列表中某个元素"
alphabet_list["ifelse"] = "条件测试，条件比较多还有elif"
for method, alphabet in alphabet_list.items():
	print(method+":\n"+alphabet)
#6-5
geometry={"changjiang": "china", "huanghe": "china","nile": "egypt"}
for river, country in geometry.items():
	print("the " + river.title() + " runs through " + country.title())
for river in geometry:
	print(river.title())
for country in geometry.values():
	print(country.title())
#6-6
poll_list=["jen","sarah","mini","paul"]
for name in poll_list:
	if name in favourite_languages:
		print("thank you, " + name.title())
	else:
		print("please join us, " + name.title())
#6-7
friend1 = {
    "first_name": "angel", 
    "last_name": "tanpson", 
    "age": 89, 
    "city": "beijing",
    }
friend2 = {
    "first_name": "angela", 
    "last_name": "shinpuson", 
    "age": 12, 
    "city": "xianggang",
    }
people = [friend,friend1,friend2]
for info in people:
	print(info)
#6-8
eaststreet = {"samoye": "mickey", "hashiqi": "gaofei", "dubin": "olive"}
weststreet = {"jiwawa": "daily", "tianyuan": "lubin","lageladuo": "cuidi"}
pets = [eaststreet,weststreet]
for pet in pets:
	print(pet)
#6-9
favourite_places = {
    "mom": ["nanjing", "lasa"], 
    "me": ["shenzhen", "suzhou"],
    "dad": ["qinghai", "changzhou"],
    }
for name, places in favourite_places.items():
	print(name + places + "\n")
#6-10
favourite_nums = {"mom": [66, 12], "dad": 45, "yu": [36, 72], "me": [8, 1, 9]}
for name, num in favourite_nums.items():
	print(name + str(num) + "\n")
#6-11
cities = {
    "beijing": 
    {"country": "china", "population": 140, "fact": "beauty"},
    "london":
    {"country": "british", "population": 12, "fact": "rainy"},
    "newyork":
    {"country": "america", "population": 20, "fact": "large"},
    }
for name, describe in cities.items():
	print(name + describe + "\n")

